﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using GPSTrackingDBV2.Entities;
using GPSTrackingDBV2.Data;

#endregion

namespace GPSTrackingDBV2.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="AdministratorsByDepartmentsProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class AdministratorsByDepartmentsProviderBaseCore : EntityProviderBase<GPSTrackingDBV2.Entities.AdministratorsByDepartments, GPSTrackingDBV2.Entities.AdministratorsByDepartmentsKey>
	{		
		#region Get from Many To Many Relationship Functions
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, GPSTrackingDBV2.Entities.AdministratorsByDepartmentsKey key)
		{
			return Delete(transactionManager, key.AdminUsername, key.CompanyId, key.DepartmentId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="_adminUsername">. Primary Key.</param>
		/// <param name="_companyId">. Primary Key.</param>
		/// <param name="_departmentId">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(System.String _adminUsername, System.Int32 _companyId, System.Int32 _departmentId)
		{
			return Delete(null, _adminUsername, _companyId, _departmentId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_adminUsername">. Primary Key.</param>
		/// <param name="_companyId">. Primary Key.</param>
		/// <param name="_departmentId">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, System.String _adminUsername, System.Int32 _companyId, System.Int32 _departmentId);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_AdministratorsByDepartments_Administrators key.
		///		FK_AdministratorsByDepartments_Administrators Description: 
		/// </summary>
		/// <param name="_adminUsername"></param>
		/// <param name="_companyId"></param>
		/// <returns>Returns a typed collection of GPSTrackingDBV2.Entities.AdministratorsByDepartments objects.</returns>
		public TList<AdministratorsByDepartments> GetByAdminUsernameCompanyId(System.String _adminUsername, System.Int32 _companyId)
		{
			int count = -1;
			return GetByAdminUsernameCompanyId(_adminUsername, _companyId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_AdministratorsByDepartments_Administrators key.
		///		FK_AdministratorsByDepartments_Administrators Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_adminUsername"></param>
		/// <param name="_companyId"></param>
		/// <returns>Returns a typed collection of GPSTrackingDBV2.Entities.AdministratorsByDepartments objects.</returns>
		/// <remarks></remarks>
		public TList<AdministratorsByDepartments> GetByAdminUsernameCompanyId(TransactionManager transactionManager, System.String _adminUsername, System.Int32 _companyId)
		{
			int count = -1;
			return GetByAdminUsernameCompanyId(transactionManager, _adminUsername, _companyId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_AdministratorsByDepartments_Administrators key.
		///		FK_AdministratorsByDepartments_Administrators Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_adminUsername"></param>
		/// <param name="_companyId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GPSTrackingDBV2.Entities.AdministratorsByDepartments objects.</returns>
		public TList<AdministratorsByDepartments> GetByAdminUsernameCompanyId(TransactionManager transactionManager, System.String _adminUsername, System.Int32 _companyId, int start, int pageLength)
		{
			int count = -1;
			return GetByAdminUsernameCompanyId(transactionManager, _adminUsername, _companyId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_AdministratorsByDepartments_Administrators key.
		///		fkAdministratorsByDepartmentsAdministrators Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_adminUsername"></param>
		/// <param name="_companyId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GPSTrackingDBV2.Entities.AdministratorsByDepartments objects.</returns>
		public TList<AdministratorsByDepartments> GetByAdminUsernameCompanyId(System.String _adminUsername, System.Int32 _companyId, int start, int pageLength)
		{
			int count =  -1;
			return GetByAdminUsernameCompanyId(null, _adminUsername, _companyId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_AdministratorsByDepartments_Administrators key.
		///		fkAdministratorsByDepartmentsAdministrators Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_adminUsername"></param>
		/// <param name="_companyId"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GPSTrackingDBV2.Entities.AdministratorsByDepartments objects.</returns>
		public TList<AdministratorsByDepartments> GetByAdminUsernameCompanyId(System.String _adminUsername, System.Int32 _companyId, int start, int pageLength,out int count)
		{
			return GetByAdminUsernameCompanyId(null, _adminUsername, _companyId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_AdministratorsByDepartments_Administrators key.
		///		FK_AdministratorsByDepartments_Administrators Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_adminUsername"></param>
		/// <param name="_companyId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of GPSTrackingDBV2.Entities.AdministratorsByDepartments objects.</returns>
		public abstract TList<AdministratorsByDepartments> GetByAdminUsernameCompanyId(TransactionManager transactionManager, System.String _adminUsername, System.Int32 _companyId, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_AdministratorsByDepartments_Departments key.
		///		FK_AdministratorsByDepartments_Departments Description: 
		/// </summary>
		/// <param name="_departmentId"></param>
		/// <returns>Returns a typed collection of GPSTrackingDBV2.Entities.AdministratorsByDepartments objects.</returns>
		public TList<AdministratorsByDepartments> GetByDepartmentId(System.Int32 _departmentId)
		{
			int count = -1;
			return GetByDepartmentId(_departmentId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_AdministratorsByDepartments_Departments key.
		///		FK_AdministratorsByDepartments_Departments Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_departmentId"></param>
		/// <returns>Returns a typed collection of GPSTrackingDBV2.Entities.AdministratorsByDepartments objects.</returns>
		/// <remarks></remarks>
		public TList<AdministratorsByDepartments> GetByDepartmentId(TransactionManager transactionManager, System.Int32 _departmentId)
		{
			int count = -1;
			return GetByDepartmentId(transactionManager, _departmentId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_AdministratorsByDepartments_Departments key.
		///		FK_AdministratorsByDepartments_Departments Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_departmentId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GPSTrackingDBV2.Entities.AdministratorsByDepartments objects.</returns>
		public TList<AdministratorsByDepartments> GetByDepartmentId(TransactionManager transactionManager, System.Int32 _departmentId, int start, int pageLength)
		{
			int count = -1;
			return GetByDepartmentId(transactionManager, _departmentId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_AdministratorsByDepartments_Departments key.
		///		fkAdministratorsByDepartmentsDepartments Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_departmentId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GPSTrackingDBV2.Entities.AdministratorsByDepartments objects.</returns>
		public TList<AdministratorsByDepartments> GetByDepartmentId(System.Int32 _departmentId, int start, int pageLength)
		{
			int count =  -1;
			return GetByDepartmentId(null, _departmentId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_AdministratorsByDepartments_Departments key.
		///		fkAdministratorsByDepartmentsDepartments Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_departmentId"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GPSTrackingDBV2.Entities.AdministratorsByDepartments objects.</returns>
		public TList<AdministratorsByDepartments> GetByDepartmentId(System.Int32 _departmentId, int start, int pageLength,out int count)
		{
			return GetByDepartmentId(null, _departmentId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_AdministratorsByDepartments_Departments key.
		///		FK_AdministratorsByDepartments_Departments Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_departmentId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of GPSTrackingDBV2.Entities.AdministratorsByDepartments objects.</returns>
		public abstract TList<AdministratorsByDepartments> GetByDepartmentId(TransactionManager transactionManager, System.Int32 _departmentId, int start, int pageLength, out int count);
		
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override GPSTrackingDBV2.Entities.AdministratorsByDepartments Get(TransactionManager transactionManager, GPSTrackingDBV2.Entities.AdministratorsByDepartmentsKey key, int start, int pageLength)
		{
			return GetByAdminUsernameCompanyIdDepartmentId(transactionManager, key.AdminUsername, key.CompanyId, key.DepartmentId, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key PK_AdministratorsByDepartments index.
		/// </summary>
		/// <param name="_adminUsername"></param>
		/// <param name="_companyId"></param>
		/// <param name="_departmentId"></param>
		/// <returns>Returns an instance of the <see cref="GPSTrackingDBV2.Entities.AdministratorsByDepartments"/> class.</returns>
		public GPSTrackingDBV2.Entities.AdministratorsByDepartments GetByAdminUsernameCompanyIdDepartmentId(System.String _adminUsername, System.Int32 _companyId, System.Int32 _departmentId)
		{
			int count = -1;
			return GetByAdminUsernameCompanyIdDepartmentId(null,_adminUsername, _companyId, _departmentId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_AdministratorsByDepartments index.
		/// </summary>
		/// <param name="_adminUsername"></param>
		/// <param name="_companyId"></param>
		/// <param name="_departmentId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="GPSTrackingDBV2.Entities.AdministratorsByDepartments"/> class.</returns>
		public GPSTrackingDBV2.Entities.AdministratorsByDepartments GetByAdminUsernameCompanyIdDepartmentId(System.String _adminUsername, System.Int32 _companyId, System.Int32 _departmentId, int start, int pageLength)
		{
			int count = -1;
			return GetByAdminUsernameCompanyIdDepartmentId(null, _adminUsername, _companyId, _departmentId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_AdministratorsByDepartments index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_adminUsername"></param>
		/// <param name="_companyId"></param>
		/// <param name="_departmentId"></param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="GPSTrackingDBV2.Entities.AdministratorsByDepartments"/> class.</returns>
		public GPSTrackingDBV2.Entities.AdministratorsByDepartments GetByAdminUsernameCompanyIdDepartmentId(TransactionManager transactionManager, System.String _adminUsername, System.Int32 _companyId, System.Int32 _departmentId)
		{
			int count = -1;
			return GetByAdminUsernameCompanyIdDepartmentId(transactionManager, _adminUsername, _companyId, _departmentId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_AdministratorsByDepartments index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_adminUsername"></param>
		/// <param name="_companyId"></param>
		/// <param name="_departmentId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="GPSTrackingDBV2.Entities.AdministratorsByDepartments"/> class.</returns>
		public GPSTrackingDBV2.Entities.AdministratorsByDepartments GetByAdminUsernameCompanyIdDepartmentId(TransactionManager transactionManager, System.String _adminUsername, System.Int32 _companyId, System.Int32 _departmentId, int start, int pageLength)
		{
			int count = -1;
			return GetByAdminUsernameCompanyIdDepartmentId(transactionManager, _adminUsername, _companyId, _departmentId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_AdministratorsByDepartments index.
		/// </summary>
		/// <param name="_adminUsername"></param>
		/// <param name="_companyId"></param>
		/// <param name="_departmentId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="GPSTrackingDBV2.Entities.AdministratorsByDepartments"/> class.</returns>
		public GPSTrackingDBV2.Entities.AdministratorsByDepartments GetByAdminUsernameCompanyIdDepartmentId(System.String _adminUsername, System.Int32 _companyId, System.Int32 _departmentId, int start, int pageLength, out int count)
		{
			return GetByAdminUsernameCompanyIdDepartmentId(null, _adminUsername, _companyId, _departmentId, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_AdministratorsByDepartments index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_adminUsername"></param>
		/// <param name="_companyId"></param>
		/// <param name="_departmentId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="GPSTrackingDBV2.Entities.AdministratorsByDepartments"/> class.</returns>
		public abstract GPSTrackingDBV2.Entities.AdministratorsByDepartments GetByAdminUsernameCompanyIdDepartmentId(TransactionManager transactionManager, System.String _adminUsername, System.Int32 _companyId, System.Int32 _departmentId, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a TList&lt;AdministratorsByDepartments&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="TList&lt;AdministratorsByDepartments&gt;"/></returns>
		public static TList<AdministratorsByDepartments> Fill(IDataReader reader, TList<AdministratorsByDepartments> rows, int start, int pageLength)
		{
			NetTiersProvider currentProvider = DataRepository.Provider;
            bool useEntityFactory = currentProvider.UseEntityFactory;
            bool enableEntityTracking = currentProvider.EnableEntityTracking;
            LoadPolicy currentLoadPolicy = currentProvider.CurrentLoadPolicy;
			Type entityCreationFactoryType = currentProvider.EntityCreationalFactoryType;
			
			// advance to the starting row
			for (int i = 0; i < start; i++)
			{
				if (!reader.Read())
				return rows; // not enough rows, just return
			}
			for (int i = 0; i < pageLength; i++)
			{
				if (!reader.Read())
					break; // we are done
					
				string key = null;
				
				GPSTrackingDBV2.Entities.AdministratorsByDepartments c = null;
				if (useEntityFactory)
				{
					key = new System.Text.StringBuilder("AdministratorsByDepartments")
					.Append("|").Append((System.String)reader[((int)AdministratorsByDepartmentsColumn.AdminUsername - 1)])
					.Append("|").Append((System.Int32)reader[((int)AdministratorsByDepartmentsColumn.CompanyId - 1)])
					.Append("|").Append((System.Int32)reader[((int)AdministratorsByDepartmentsColumn.DepartmentId - 1)]).ToString();
					c = EntityManager.LocateOrCreate<AdministratorsByDepartments>(
					key.ToString(), // EntityTrackingKey
					"AdministratorsByDepartments",  //Creational Type
					entityCreationFactoryType,  //Factory used to create entity
					enableEntityTracking); // Track this entity?
				}
				else
				{
					c = new GPSTrackingDBV2.Entities.AdministratorsByDepartments();
				}
				
				if (!enableEntityTracking ||
					c.EntityState == EntityState.Added ||
					(enableEntityTracking &&
					
						(
							(currentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
							(currentLoadPolicy == LoadPolicy.DiscardChanges && c.EntityState != EntityState.Unchanged)
						)
					))
				{
					c.SuppressEntityEvents = true;
					c.AdminUsername = (System.String)reader[((int)AdministratorsByDepartmentsColumn.AdminUsername - 1)];
					c.OriginalAdminUsername = c.AdminUsername;
					c.CompanyId = (System.Int32)reader[((int)AdministratorsByDepartmentsColumn.CompanyId - 1)];
					c.OriginalCompanyId = c.CompanyId;
					c.DepartmentId = (System.Int32)reader[((int)AdministratorsByDepartmentsColumn.DepartmentId - 1)];
					c.OriginalDepartmentId = c.DepartmentId;
					c.EntityTrackingKey = key;
					c.AcceptChanges();
					c.SuppressEntityEvents = false;
				}
				rows.Add(c);
			}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="GPSTrackingDBV2.Entities.AdministratorsByDepartments"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="GPSTrackingDBV2.Entities.AdministratorsByDepartments"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, GPSTrackingDBV2.Entities.AdministratorsByDepartments entity)
		{
			if (!reader.Read()) return;
			
			entity.AdminUsername = (System.String)reader[((int)AdministratorsByDepartmentsColumn.AdminUsername - 1)];
			entity.OriginalAdminUsername = (System.String)reader["AdminUsername"];
			entity.CompanyId = (System.Int32)reader[((int)AdministratorsByDepartmentsColumn.CompanyId - 1)];
			entity.OriginalCompanyId = (System.Int32)reader["CompanyID"];
			entity.DepartmentId = (System.Int32)reader[((int)AdministratorsByDepartmentsColumn.DepartmentId - 1)];
			entity.OriginalDepartmentId = (System.Int32)reader["DepartmentID"];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="GPSTrackingDBV2.Entities.AdministratorsByDepartments"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="GPSTrackingDBV2.Entities.AdministratorsByDepartments"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, GPSTrackingDBV2.Entities.AdministratorsByDepartments entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.AdminUsername = (System.String)dataRow["AdminUsername"];
			entity.OriginalAdminUsername = (System.String)dataRow["AdminUsername"];
			entity.CompanyId = (System.Int32)dataRow["CompanyID"];
			entity.OriginalCompanyId = (System.Int32)dataRow["CompanyID"];
			entity.DepartmentId = (System.Int32)dataRow["DepartmentID"];
			entity.OriginalDepartmentId = (System.Int32)dataRow["DepartmentID"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="GPSTrackingDBV2.Entities.AdministratorsByDepartments"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">GPSTrackingDBV2.Entities.AdministratorsByDepartments Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		public override void DeepLoad(TransactionManager transactionManager, GPSTrackingDBV2.Entities.AdministratorsByDepartments entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;

			#region AdminUsernameCompanyIdSource	
			if (CanDeepLoad(entity, "Administrators|AdminUsernameCompanyIdSource", deepLoadType, innerList) 
				&& entity.AdminUsernameCompanyIdSource == null)
			{
				object[] pkItems = new object[2];
				pkItems[0] = entity.AdminUsername;
				pkItems[1] = entity.CompanyId;
				Administrators tmpEntity = EntityManager.LocateEntity<Administrators>(EntityLocator.ConstructKeyFromPkItems(typeof(Administrators), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.AdminUsernameCompanyIdSource = tmpEntity;
				else
					entity.AdminUsernameCompanyIdSource = DataRepository.AdministratorsProvider.GetByAdminUsernameCompanyId(transactionManager, entity.AdminUsername, entity.CompanyId);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'AdminUsernameCompanyIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.AdminUsernameCompanyIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.AdministratorsProvider.DeepLoad(transactionManager, entity.AdminUsernameCompanyIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion AdminUsernameCompanyIdSource

			#region DepartmentIdSource	
			if (CanDeepLoad(entity, "Departments|DepartmentIdSource", deepLoadType, innerList) 
				&& entity.DepartmentIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.DepartmentId;
				Departments tmpEntity = EntityManager.LocateEntity<Departments>(EntityLocator.ConstructKeyFromPkItems(typeof(Departments), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.DepartmentIdSource = tmpEntity;
				else
					entity.DepartmentIdSource = DataRepository.DepartmentsProvider.GetByDepartmentId(transactionManager, entity.DepartmentId);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'DepartmentIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.DepartmentIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.DepartmentsProvider.DeepLoad(transactionManager, entity.DepartmentIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion DepartmentIdSource
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the GPSTrackingDBV2.Entities.AdministratorsByDepartments object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">GPSTrackingDBV2.Entities.AdministratorsByDepartments instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">GPSTrackingDBV2.Entities.AdministratorsByDepartments Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		public override bool DeepSave(TransactionManager transactionManager, GPSTrackingDBV2.Entities.AdministratorsByDepartments entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			
			#region AdminUsernameCompanyIdSource
			if (CanDeepSave(entity, "Administrators|AdminUsernameCompanyIdSource", deepSaveType, innerList) 
				&& entity.AdminUsernameCompanyIdSource != null)
			{
				DataRepository.AdministratorsProvider.Save(transactionManager, entity.AdminUsernameCompanyIdSource);
				entity.AdminUsername = entity.AdminUsernameCompanyIdSource.AdminUsername;
				entity.CompanyId = entity.AdminUsernameCompanyIdSource.CompanyId;
			}
			#endregion 
			
			#region DepartmentIdSource
			if (CanDeepSave(entity, "Departments|DepartmentIdSource", deepSaveType, innerList) 
				&& entity.DepartmentIdSource != null)
			{
				DataRepository.DepartmentsProvider.Save(transactionManager, entity.DepartmentIdSource);
				entity.DepartmentId = entity.DepartmentIdSource.DepartmentId;
			}
			#endregion 
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region AdministratorsByDepartmentsChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>GPSTrackingDBV2.Entities.AdministratorsByDepartments</c>
	///</summary>
	public enum AdministratorsByDepartmentsChildEntityTypes
	{
		
		///<summary>
		/// Composite Property for <c>Administrators</c> at AdminUsernameCompanyIdSource
		///</summary>
		[ChildEntityType(typeof(Administrators))]
		Administrators,
			
		///<summary>
		/// Composite Property for <c>Departments</c> at DepartmentIdSource
		///</summary>
		[ChildEntityType(typeof(Departments))]
		Departments,
		}
	
	#endregion AdministratorsByDepartmentsChildEntityTypes
	
	#region AdministratorsByDepartmentsFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;AdministratorsByDepartmentsColumn&gt;"/> class
	/// that is used exclusively with a <see cref="AdministratorsByDepartments"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class AdministratorsByDepartmentsFilterBuilder : SqlFilterBuilder<AdministratorsByDepartmentsColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the AdministratorsByDepartmentsFilterBuilder class.
		/// </summary>
		public AdministratorsByDepartmentsFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the AdministratorsByDepartmentsFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public AdministratorsByDepartmentsFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the AdministratorsByDepartmentsFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public AdministratorsByDepartmentsFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion AdministratorsByDepartmentsFilterBuilder
	
	#region AdministratorsByDepartmentsParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;AdministratorsByDepartmentsColumn&gt;"/> class
	/// that is used exclusively with a <see cref="AdministratorsByDepartments"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class AdministratorsByDepartmentsParameterBuilder : ParameterizedSqlFilterBuilder<AdministratorsByDepartmentsColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the AdministratorsByDepartmentsParameterBuilder class.
		/// </summary>
		public AdministratorsByDepartmentsParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the AdministratorsByDepartmentsParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public AdministratorsByDepartmentsParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the AdministratorsByDepartmentsParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public AdministratorsByDepartmentsParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion AdministratorsByDepartmentsParameterBuilder
	
	#region AdministratorsByDepartmentsSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;AdministratorsByDepartmentsColumn&gt;"/> class
	/// that is used exclusively with a <see cref="AdministratorsByDepartments"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class AdministratorsByDepartmentsSortBuilder : SqlSortBuilder<AdministratorsByDepartmentsColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the AdministratorsByDepartmentsSqlSortBuilder class.
		/// </summary>
		public AdministratorsByDepartmentsSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion AdministratorsByDepartmentsSortBuilder
	
} // end namespace
